#========================================
#    author: Changlong.Zang
#      mail: zclongpop123@163.com
#      time: Tue Apr 18 10:49:59 2017
#========================================
try:
    from PyQt5 import QtCore
except ImportError:
    from PyQt4 import QtCore
import maya.OpenMayaUI as OpenMayaUI
import maya.cmds
import sip
#--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
def get_maya_window():
    '''
    return maya window by Qt object..
    '''
    maya_window = OpenMayaUI.MQtUtil.mainWindow()
    if maya_window:
        return sip.wrapinstance(long(maya_window), QtCore.QObject)





def windows_exists(name):
    '''
    get named window, if window exists, return true; if not, return false..
    '''
    widget = OpenMayaUI.MQtUtil.findWindow(name)
    if not widget:
        return False

    wnd = sip.wrapinstance(long(widget), QtCore.QObject)
    wnd.showNormal()
    wnd.activateWindow()

    return True





def undo_decorator(func):
    '''
    To fix maya can't undo bug..
    '''
    def doIt(*args, **kvargs):
        maya.cmds.undoInfo(openChunk=True)
        func(*args, **kvargs)
        maya.cmds.undoInfo(closeChunk=True)
    return doIt
